package com.ian.enums;


import lombok.AllArgsConstructor;
import lombok.Getter;

@AllArgsConstructor
@Getter
public enum ApiStatusEnum {


    // OK(0, "Return the Original 'result' Field Only, HTTP Status Code will be 200"),
    Success(0, "Return the Raw Struct-Data with Fields 'code', 'message' and 'result', HTTP Status Code will be 200", "SUCCESS"),
    Success2(0, "Return the Raw Struct-Data with Fields 'code', 'message' and 'result', HTTP Status Code will be 200", "登录成功"),
    ResultView(100, "Return the Raw Struct-Data with Fields 'code', 'message' and 'result', HTTP Status Code will be 200", "ResultView"),
    Error(-1, "Return the Raw Struct-Data of ObjectResult with Fields 'code', 'message' and 'result', HTTP Status Code will be 500", "Error"),
    Exception(-2, "Return the Raw Struct-Data of ExceptionResult with Fields 'code', 'message' and 'result', HTTP Status Code will be 500", "Exception"),
    ExceptionResult(-3, "Return the Raw Struct-Data of ExceptionResult with Fields 'code', 'message' and 'result', HTTP Status Code will be 200", "ExceptionResult"),
    WarningResult(-4, "Return the Raw Struct-Data of WarningResult with Fields 'code', 'message' and 'result', HTTP Status Code will be 200", "WarningResult"),
    BadRequest(400, "HTTP Defined Code: 400", "BadRequest"),
    UnauthorizedAccess(401, "HTTP Defined Code: 401", "UnauthorizedAccess"),
    NotFound(404, "HTTP Defined Code: 404", "NotFound"),
    MethodNotAllowed(405, "HTTP Defined Code: 405", "MethodNotAllowed"),
    InternalServerError(500, "HTTP Defined Code: 500", "InternalServerError"),
    GatewayTimeout(504, "HTTP Defined Code: 504", "Gateway Timeout"),
    ;
    private int code;
    private String desc;
    private String message;

    /**
     * 描述: 通过编码获取对应消息
     *
     * @param code  code
     * @return {@link String}
     * @author wenxudong
     * @date 2021/12/23 15:50
     */
    public static String getMessage(Integer code) {
        if (code == null) {
            return null;
        }
        ApiStatusEnum[] apiStatusEnums = values();
        for (ApiStatusEnum apiStatusEnum : apiStatusEnums) {
            if (apiStatusEnum.getCode() == code) {
                return apiStatusEnum.getMessage();
            }
        }
        return null;
    }
}
